-
Notifications
You must be signed in to change notification settings - Fork 659
Add kotlin.time.Instant serializers #2945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
For |
For now, you can use |
Something like this? JetBrains/kotlin#5412 |
Note that even after merging Kotlin PR, changes in this one are required, because compiler is not updated instantly |
After moving `Instant` from `kotlinx.datetime` to `kotlin.time`, we also need to preserve it having a default `kotlinx.serialization` serializer. See Kotlin/KEEP#387 The corresponding request in `kotlinx.serialization`: Kotlin/kotlinx.serialization#2945
Sure thing! Are there any other changes I should make in addition to that? For example, I copied the test from |
…rializers After moving `Instant` from `kotlinx.datetime` to `kotlin.time`, we also need to preserve it having a default `kotlinx.serialization` serializer. See Kotlin/KEEP#387 The corresponding request in `kotlinx.serialization`: Kotlin/kotlinx.serialization#2945 Additionally, fix a test that was not being run correctly. Merge-request: KT-MR-20493 Merged-by: Dmitry Khalanskiy <dmitry.khalanskiy@jetbrains.com>
core/commonMain/src/kotlinx/serialization/builtins/InstantComponentSerializer.kt
Show resolved
Hide resolved
@@ -251,6 +253,19 @@ public fun UShort.Companion.serializer(): KSerializer<UShort> = UShortSerializer | |||
*/ | |||
public fun Duration.Companion.serializer(): KSerializer<Duration> = DurationSerializer | |||
|
|||
/** | |||
* Returns serializer for [Instant]. | |||
* It is serialized as a string that represents an instant in the format described in ISO-8601-1:2019, 5.4.2.1b). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* It is serialized as a string that represents an instant in the format described in ISO-8601-1:2019, 5.4.2.1b). | |
* It is serialized as a string that represents an instant in the format same as the result of [Instant.toString] operation, described in ISO-8601-1:2019, 5.4.2.1b. |
I think hardly anyone remembers what exactly is written in section 5.4.2.1b of a paid document
when (val index = decodeElementIndex(descriptor)) { | ||
0 -> epochSeconds = decodeLongElement(descriptor, 0) | ||
1 -> nanosecondsOfSecond = decodeIntElement(descriptor, 1) | ||
CompositeDecoder.DECODE_DONE -> break@loop // https://youtrack.jetbrains.com/issue/KT-42262 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ticket is said to be fixed in Kotlin 1.4.30
Pair(Instant.fromEpochSeconds(987654321, 0), | ||
"\"2001-04-19T04:25:21Z\""), | ||
)) { | ||
assertEquals(json, Json.encodeToString(serializer, instant)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use assertJsonFormAndRestored
test helper function as in e.g. here:
kotlinx.serialization/formats/json-tests/commonTest/src/kotlinx/serialization/features/UuidTest.kt
Line 18 in fa797bc
assertJsonFormAndRestored(Uuid.serializer(), uuid, "\"$uuid\"") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would check that all Json flavors (string, inputStream, JsonElement) behave identically
val sb = StringBuilder() | ||
val out = KeyValueOutput(sb) | ||
|
||
val instant = Instant.parse("2020-12-09T09:16:56.000124Z") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, having Json string tests is enough, but if you think these are necessary as well, you can keep them.
c28031f
to
89a6f95
Compare
89a6f95
to
7d5981e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to squash commits on merging
core/commonMain/src/kotlinx/serialization/builtins/BuiltinSerializers.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added some suggestions on augmentation/correctness.
else -> throw SerializationException("Unexpected index: $index") | ||
} | ||
} | ||
if (epochSeconds == null) throw MissingFieldException( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid boxing it may be better to either have a separate primitive value that records whether epochSeconds was seen, or have a "sentinel" value that is not a valid Instant (e.g. Long.MAX
or Long.MIN
)
if (value.nanosecondsOfSecond != 0) { | ||
encodeIntElement(descriptor, 1, value.nanosecondsOfSecond) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have a call to shouldEncodeElementDefault
as it is up to the format to decide whether or not to encode things (while this doesn't matter for Json it would for a fixed length format).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It depends on whether we really want to include nanoseconds:0
in the output even with encodeDefaults = true
.
Current behavior would be equal to having @EncodeDefault(NEVER)
annotation on Instant.nanosecondsOfSecond
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sandwwraith The issue is for a fixed length format that requires all attributes to be serialized (for example Android's Parcelable). In such case there must be bits written to represent the default value. It is not possible to write a placeholder as any placeholder value could be a valid value, so either the actual default is written or a marker is written (changing the wire format to add a marker byte).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sandwwraith I've played around a bit and added binary tests to the jsonTests in #2979 . This is based upon the EfficientBinaryFormat
from the documentation (but cross platform), and for now only in the test code (it was not designed to be used as a production format). To make the tests actually pass it is absolutely necessary to return false
to shouldEncodeElementDefault
(and EncodeDefault(Mode.NEVER)
is not valid for this format).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what the problem is. Descriptor says that nanosecondsOfSecond
is optional, so there is no contradiction here. I would say that supporting @EncodeDefault(Mode.NEVER)
is a reasonable expectation from any format, including binary. Deserializer would be also fine if format would never return 1
from the decodeElementIndex
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To show it breaks I have created another branch applying the binary test to the InstantSerializer:
https://github.com/pdvrieze/kotlinx.serialization/tree/pdvrieze/instant-serializers-with-binary-test
This test fails to decode because it tries to decode the nanosecondsOfSecond
component.
Btw. I've also updated the branch underlying #2979. It now triggers more often (and the binary format has been rewritten to support out-of-order serialization). There were two sets of changes needed. The error message test needed to be adjusted to check the correct message. More interesting is that for JsonCustomSerializersTest
all custom serializers needed to be fixed to call shouldEncodeElementDefault
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean. Do you have any real-world examples of such formats? IIRC, even binary formats with schema (such as Protobuf or Avro) have some way of denoting the id of the next element in the stream (e.g., protoId).
Still, it would mean that such a format is unable to support @EncodeDefault(NEVER)
, which IMO limits its usability with kotlinx.serialization.
Besides, InstantComponentSerializer
is not the default. I imagine that for such a format one can easily write InstantComponentWithMandatoryNanosecondsSerializer
and use it instead. I highly doubt that we should sacrifice convenience for the sake of some hypothetical ultra-fast binary format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are quite some cases (not supported by kotlinx.serialization). I have looked at some examples:
- Java serialization (ObjectOutputStream) - when writing primitives no class is written, only the value
- Android Parcelable - again just writes the values, not types where not required
- FlatBuffers - It is aimed at access without parsing. The "Structs" type just groups the members.
It is also common in many binary file formats (e.g. PNG, ZIP) or binary network protocols (IP/TCP/TLS/HTTP2.0/dbus) - but even textual line separated formats (e.g. Advent of code data) would may not be self-describing. The EfficientBinaryFormat
was actually taken from the documentation (and it has this property). The key factor is whether the format is self-describing (in other words, can be parsed without access to a schema).
The fix for this case would be where the format can influence behaviour (by default it returns false and constant folding should be able to easily optimize the call away):
if (value.nanosecondsOfSecond != 0 || shouldEncodeElementDefault(descriptor, 1)) {
As to @EncodeDefault(NEVER)
, I would say this has been implemented incorrectly (and possibly misnamed - AVOID
would be better). The implementation would be better if shouldEncodeElementDefault
were invoked in all cases, but this being an overload that passes the "never" (or avoid) value. The format could then return true
if the storage is invalid when defaults are omitted. This approach is probably preferable over requiring a SerializationStrategy
to somehow be able to produce default values on request (and certainly more binary compatible).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're unlikely to support Java serialization. Parcelable is a good example, but usually people just use @Parcelize
annotation.
As I said, since this is a non-default serializer, IMO it is acceptable to sacrifice supporting non-standard formats in favor of better representation in Json (which is a primary aim for this serializer). If there would be problems with such an approach, we can always either fix them (as long as it is experimental) or introduce other serializer (e.g. InstantBinaryComponentSerializer
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just calling the shouldEncodeElementDefault will return false in the normal json case so the json format will be the same. Most likely the optimizer will make the check disappear as well. Also note that this is what the generated serializers do. On the never annotation, that is is still user controlled.
import kotlin.reflect.typeOf | ||
|
||
@OptIn(ExperimentalTime::class) | ||
class InstantSerializationTest: JsonTestBase() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be worthwhile to also test on another format that is not Json
(or JsonLike
)
for ((instant, json) in listOf( | ||
Pair(Instant.fromEpochSeconds(1607505416, 124000), | ||
"\"2020-12-09T09:16:56.000124Z\""), | ||
Pair(Instant.fromEpochSeconds(-1607505416, -124000), | ||
"\"1919-01-23T14:43:03.999876Z\""), | ||
Pair(Instant.fromEpochSeconds(987654321, 123456789), | ||
"\"2001-04-19T04:25:21.123456789Z\""), | ||
Pair(Instant.fromEpochSeconds(987654321, 0), | ||
"\"2001-04-19T04:25:21Z\""), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should include some values with non-utc timezones (especially ones with strange offsets like India). And include the fraction handling with millis, or less than 3 digits in the fraction of seconds.
7d5981e
to
7587980
Compare
// by default, `nanosecondsOfSecond` is optional | ||
assertJsonFormAndRestored(serializer, Instant.fromEpochSeconds(987654321, 0), | ||
"{\"epochSeconds\":987654321}", Json { }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment might clarify that the default test json instance has encoding defaults enabled. the nanosecondsOfSecond
element is always optional, but the format decides whether to serialize the default value. You might replace Json {}
with Json(default) { encodeDefaults = false }
to both take in the remainder of the default test configuration and communicate that it set to false here.
Any chance to get a review (and a release) soon? |
gradle/libs.versions.toml
Outdated
@@ -1,7 +1,7 @@ | |||
[versions] | |||
kotlin = "2.1.20" | |||
kover = "0.8.2" | |||
dokka = "2.0.0-Beta" | |||
dokka = "2.0.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see some unrelated Dokka commits got there, maybe you need to do a rebase
Json.decodeFromString(serializer, | ||
"{\"epochSeconds\":987654321,\"nanosecondsOfSecond\":0}")) | ||
// as does not having a `"nanosecondsOfSecond"` field if `encodeDefaults` is true | ||
assertEquals(Instant.fromEpochSeconds(987654321, 0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also check that default
Json (the one with encodeDefaults=true) produces "{\"epochSeconds\":987654321,\"nanosecondsOfSecond\":0}"
when requested
Can be merged after moving to Kotlin 2.1.20, which introduces kotlin.time.Instant. kotlinx.datetime.Instant entered the stdlib as kotlin.time.Instant, and so kotlinx.serialization takes over its serializers. See Kotlin/KEEP#387
5efb20f
to
9c18b80
Compare
Use |
It's not annotated for the same reason |
@valeriyo, please share a sample project where the issue happens. I couldn't make it reproduce during testing (#3026 (comment)). |
@valeriyo, the project you linked compiles without errors and the reason why IDE highlights the code despite it being perfectly fine was described here: #3026 (comment). |
Add kotlin.time.Instant serializers kotlinx.datetime.Instant entered the stdlib as kotlin.time.Instant, and so kotlinx.serialization takes over its serializers. (toString() one and ComponentSerializer). See Kotlin/KEEP#387 * Move the tests for the Instant serializers Original version: https://github.com/Kotlin/kotlinx-datetime/blob/72681c2acaf9addf5effdef8ecd0975f6f7d10a7/serialization/common/test/InstantSerializationTest.kt * Improve the documentation
| Package | Type | Package file | Manager | Update | Change | |---|---|---|---|---|---| | [io.modelcontextprotocol:kotlin-sdk](https://github.com/modelcontextprotocol/kotlin-sdk) | dependencies | misk/gradle/libs.versions.toml | gradle | minor | `0.5.0` -> `0.6.0` | | [org.jetbrains.kotlinx:kotlinx-serialization-json](https://github.com/Kotlin/kotlinx.serialization) | dependencies | misk/gradle/libs.versions.toml | gradle | minor | `1.7.3` -> `1.9.0` | | [org.jetbrains.kotlinx:kotlinx-serialization-core](https://github.com/Kotlin/kotlinx.serialization) | dependencies | misk/gradle/libs.versions.toml | gradle | minor | `1.7.3` -> `1.9.0` | | [com.google.apis:google-api-services-storage](http://nexus.sonatype.org/oss-repository-hosting.html) ([source](http://svn.sonatype.org/spice/tags/oss-parent-7)) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `v1-rev20250718-2.0.0` -> `v1-rev20250814-2.0.0` | | [software.amazon.awssdk:sdk-core](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.32.23` -> `2.32.24` | | [software.amazon.awssdk:sqs](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.32.23` -> `2.32.24` | | [software.amazon.awssdk:regions](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.32.23` -> `2.32.24` | | [software.amazon.awssdk:dynamodb-enhanced](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.32.23` -> `2.32.24` | | [software.amazon.awssdk:dynamodb](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.32.23` -> `2.32.24` | | [software.amazon.awssdk:aws-core](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.32.23` -> `2.32.24` | | [software.amazon.awssdk:bom](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.32.23` -> `2.32.24` | | [software.amazon.awssdk:auth](https://aws.amazon.com/sdkforjava) | dependencies | misk/gradle/libs.versions.toml | gradle | patch | `2.32.23` -> `2.32.24` | --- ### Release Notes <details> <summary>modelcontextprotocol/kotlin-sdk (io.modelcontextprotocol:kotlin-sdk)</summary> ### [`v0.6.0`](https://github.com/modelcontextprotocol/kotlin-sdk/releases/tag/0.6.0) [Compare Source](modelcontextprotocol/kotlin-sdk@0.5.0...0.6.0) #### What's Changed - Update jreleaser to fix publication issue by [@​e5l](https://github.com/e5l) in modelcontextprotocol/kotlin-sdk#91 - Disable configuration cache to fix jreleaser issue by [@​e5l](https://github.com/e5l) in modelcontextprotocol/kotlin-sdk#92 - feat: Add audio type according to 2025-03-26 spec by [@​SeanChinJunKai](https://github.com/SeanChinJunKai) in modelcontextprotocol/kotlin-sdk#68 - fix(client): serialize inputSchema as input\_schema by [@​shiqicao](https://github.com/shiqicao) in modelcontextprotocol/kotlin-sdk#97 - fix(client) add encodeDefault for field with non spec default value by [@​shiqicao](https://github.com/shiqicao) in modelcontextprotocol/kotlin-sdk#99 - Make McpJson public to allow flexible protocol development by [@​parnurzeal](https://github.com/parnurzeal) in modelcontextprotocol/kotlin-sdk#103 - fix: apply `requestBuilder` headers when sending rpc messages by [@​dead8309](https://github.com/dead8309) in modelcontextprotocol/kotlin-sdk#96 - fix: Remove [@​SerialName](https://github.com/SerialName) annotation for inputSchema by [@​adamglin0](https://github.com/adamglin0) in modelcontextprotocol/kotlin-sdk#105 - add ios and wasm targets by [@​devcrocod](https://github.com/devcrocod) in modelcontextprotocol/kotlin-sdk#81 - Add dependabot by [@​StefMa](https://github.com/StefMa) in modelcontextprotocol/kotlin-sdk#121 - Bump org.jetbrains.kotlinx:kotlinx-serialization-json from 1.7.3 to 1.8.1 by [@​dependabot](https://github.com/dependabot)\[bot] in modelcontextprotocol/kotlin-sdk#127 - Bump io.github.oshai:kotlin-logging from 7.0.0 to 7.0.7 by [@​dependabot](https://github.com/dependabot)\[bot] in modelcontextprotocol/kotlin-sdk#126 - Bump org.jetbrains.kotlinx.binary-compatibility-validator from 0.17.0 to 0.18.0 by [@​dependabot](https://github.com/dependabot)\[bot] in modelcontextprotocol/kotlin-sdk#125 - update kotlin to 2.2.0 and ktor to 3.1.3 by [@​devcrocod](https://github.com/devcrocod) in modelcontextprotocol/kotlin-sdk#120 - Add client roots addition/removal API and listRoots handler by [@​ptitjes](https://github.com/ptitjes) in modelcontextprotocol/kotlin-sdk#118 - Bump org.slf4j:slf4j-simple from 2.0.16 to 2.0.17 by [@​dependabot](https://github.com/dependabot)\[bot] in modelcontextprotocol/kotlin-sdk#131 - Bump org.jetbrains.kotlinx:kotlinx-serialization-json from 1.8.1 to 1.9.0 by [@​dependabot](https://github.com/dependabot)\[bot] in modelcontextprotocol/kotlin-sdk#132 - Bump io.mockk:mockk from 1.13.13 to 1.14.4 by [@​dependabot](https://github.com/dependabot)\[bot] in modelcontextprotocol/kotlin-sdk#133 - Remove fixed suffix /sse by [@​adamglin0](https://github.com/adamglin0) in modelcontextprotocol/kotlin-sdk#108 - sse server does not process endpoint correctly when sse path is not a directory by [@​shendaxia-sm](https://github.com/shendaxia-sm) in modelcontextprotocol/kotlin-sdk#43 - Add labels to dependabot configuration for Kotlin and GitHub Actions by [@​devcrocod](https://github.com/devcrocod) in modelcontextprotocol/kotlin-sdk#135 - feat: add tool annotations according to 2025-03-26 spec by [@​SeanChinJunKai](https://github.com/SeanChinJunKai) in modelcontextprotocol/kotlin-sdk#71 - Bump ktor from 3.1.3 to 3.2.1 by [@​dependabot](https://github.com/dependabot)\[bot] in modelcontextprotocol/kotlin-sdk#140 - Bump gradle/actions from 4.0.0 to 4.4.1 by [@​dependabot](https://github.com/dependabot)\[bot] in modelcontextprotocol/kotlin-sdk#122 - Bump org.jreleaser from 1.17.0 to 1.19.0 by [@​dependabot](https://github.com/dependabot)\[bot] in modelcontextprotocol/kotlin-sdk#141 - refactor `SseClientTransport` by [@​devcrocod](https://github.com/devcrocod) in modelcontextprotocol/kotlin-sdk#142 - atomic and persistent collections for thread safety by [@​devcrocod](https://github.com/devcrocod) in modelcontextprotocol/kotlin-sdk#143 - Bump org.gradle.toolchains.foojay-resolver-convention from 0.8.0 to 1.0.0 by [@​dependabot](https://github.com/dependabot)\[bot] in modelcontextprotocol/kotlin-sdk#130 - Add support for elicitation by [@​ptitjes](https://github.com/ptitjes) in modelcontextprotocol/kotlin-sdk#138 - Add support for tool structured content and output schema by [@​ptitjes](https://github.com/ptitjes) in modelcontextprotocol/kotlin-sdk#146 - Add streamable http client transport by [@​devcrocod](https://github.com/devcrocod) in modelcontextprotocol/kotlin-sdk#147 - Refactor JSON processing to exclude "method" in serialization by [@​devcrocod](https://github.com/devcrocod) in [#​157](modelcontextprotocol/kotlin-sdk#157) - Release 0.6.0 by [@​devcrocod](https://github.com/devcrocod) in modelcontextprotocol/kotlin-sdk#149 #### New Contributors - [@​shiqicao](https://github.com/shiqicao) made their first contribution in modelcontextprotocol/kotlin-sdk#97 - [@​parnurzeal](https://github.com/parnurzeal) made their first contribution in modelcontextprotocol/kotlin-sdk#103 - [@​dead8309](https://github.com/dead8309) made their first contribution in modelcontextprotocol/kotlin-sdk#96 - [@​adamglin0](https://github.com/adamglin0) made their first contribution in modelcontextprotocol/kotlin-sdk#105 - [@​StefMa](https://github.com/StefMa) made their first contribution in modelcontextprotocol/kotlin-sdk#121 - [@​dependabot](https://github.com/dependabot)\[bot] made their first contribution in modelcontextprotocol/kotlin-sdk#127 - [@​ptitjes](https://github.com/ptitjes) made their first contribution in modelcontextprotocol/kotlin-sdk#118 - [@​shendaxia-sm](https://github.com/shendaxia-sm) made their first contribution in modelcontextprotocol/kotlin-sdk#43 **Full Changelog**: modelcontextprotocol/kotlin-sdk@0.5.0...0.6.0 </details> <details> <summary>Kotlin/kotlinx.serialization (org.jetbrains.kotlinx:kotlinx-serialization-json)</summary> ### [`v1.9.0`](https://github.com/Kotlin/kotlinx.serialization/blob/HEAD/CHANGELOG.md#190--2025-06-27) \================== This release updates Kotlin version to 2.2.0, includes several bugfixes and provides serializers for kotlin.time.Instant. #### Add kotlin.time.Instant serializers Instant class was moved from kotlinx-datetime library to Kotlin standard library. As a result, kotlinx-datetime 0.7.0 no longer has serializers for the Instant class. To use new kotlin.time.Instant class in your [@​Serializable](https://github.com/Serializable) classes, you can use this 1.9.0 kotlinx-serialization version (Kotlin 2.2 is required). You can choose between default `InstantSerializer` which uses its string representation, or specify `InstantComponentSerializer` that represents instant as its components. See details in the [PR](Kotlin/kotlinx.serialization#2945). #### Other bugfixes - Fix resize in JsonPath ([#​2995](Kotlin/kotlinx.serialization#2995)) - Fixed proguard rules for obfuscation to work correctly ([#​2983](Kotlin/kotlinx.serialization#2983)) ### [`v1.8.1`](https://github.com/Kotlin/kotlinx.serialization/blob/HEAD/CHANGELOG.md#181--2025-03-31) \================== This release updates Kotlin version to 2.1.20, while also providing several important improvements and bugfixes. #### Improvements - Implemented encoding null in key and value of a map in Protobuf ([#​2910](Kotlin/kotlinx.serialization#2910)) - Make type argument in JsonTransformingSerializer nullable ([#​2911](Kotlin/kotlinx.serialization#2911)) - Use SPDX identifier in POMs ([#​2936](Kotlin/kotlinx.serialization#2936)) (thanks to [Leon Linhart](https://github.com/TheMrMilchmann)) - Add watchosDeviceArm64 to Okio integration module ([#​2920](Kotlin/kotlinx.serialization#2920)) (thanks to [Daniel Santiago](https://github.com/danysantiago)) - Update kotlinx-io version to 0.6.0 ([#​2933](Kotlin/kotlinx.serialization#2933)) (thanks to [Piotr Krzemiński](https://github.com/krzema12)) #### Bugfixes - Fix incorrect enum coercion during deserialization from JsonElement ([#​2962](Kotlin/kotlinx.serialization#2962)) - Supply proper equals(), hashCode(), and toString() for SerialDescriptor() wrapper ([#​2942](Kotlin/kotlinx.serialization#2942)) - Do not encode empty packed collections in protobuf ([#​2907](Kotlin/kotlinx.serialization#2907)) ### [`v1.8.0`](https://github.com/Kotlin/kotlinx.serialization/blob/HEAD/CHANGELOG.md#180--2025-01-06) \================== This release contains all of the changes from 1.8.0-RC. Kotlin 2.1.0 is used as a default, while upcoming 2.1.10 is also supported. Also added small bugfixes, including speedup of ProtoWireType.from ([#​2879](Kotlin/kotlinx.serialization#2879)). </details> --- ### Configuration 📅 **Schedule**: Branch creation - "after 6pm every weekday,before 2am every weekday" in timezone Australia/Melbourne, Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Never, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://github.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). GitOrigin-RevId: 40e2f07ecd958e92e64c571d1351e91f96e71ce7
Can be merged after moving to Kotlin 2.1.20, which introduces
kotlin.time.Instant.
kotlinx.datetime.Instant entered the stdlib as kotlin.time.Instant,
and so kotlinx.serialization takes over its serializers.
See Kotlin/KEEP#387